package com.woniuedu.search.controller;



import com.woniuedu.commonutils.R;
import com.woniuedu.search.entity.Article;
//import com.woniuedu.search.mapper.ArticleMapper;
import com.woniuedu.search.serviec.ArticleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yuankaiqiang
 * @since 2022-04-20
 */
@RestController
@RequestMapping("/search")
public class ArticleController {
    @Resource(name = "article")
    private ArticleService articleService;


    //查询所有
    @GetMapping("/article/{title}/{pagenum}/{size}")
    @ApiOperation("es 文章查询")
    public R all(@PathVariable(required = false) String title,
                 @PathVariable(required = false)Integer pagenum,
                 @PathVariable(required = false)Integer size){
        //分页对象
        Pageable pageable = PageRequest.of(pagenum, size);
        Iterable<Article> all = articleService.findByAll(title,pageable);
        return R.ok().data("article",all);
    }
}
